#include "Ray3D.h"

namespace math_tools
{
	Ray3D::Ray3D()
	{
		direction_ = Vector3D(1,0,0);
		point_ = Vector3D(0,0,0);
	}

	Ray3D::Ray3D(const Vector3D & point, const Vector3D & direction)
	{
		point_ = point;
		direction_ = direction;
	}

	Ray3D::~Ray3D()
	{

	}

	// Scalar projection on the ray.
	Vector3D Ray3D::closestPoint(const Vector3D & point)
	{
		Vector3D sub = point - point_;
		return ((direction_ * (sub.dot(direction_)/direction_.mag())) + point_);
	}

	double Ray3D::distanceFrom(const Vector3D & point)
	{
		return (closestPoint(point) - point).mag();
	}

	double Ray3D::distanceFromSqr(const Vector3D & point)
	{
		return (closestPoint(point) - point).magSqr();
	}
}
